package com.yangye.niodemo.netty.self;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.EventExecutorGroup;

/**
 * @author yangye
 * @date 2020/12/24
 */
//@ChannelHandler.Sharable
public class MyInHandler extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
		System.out.println("client registered...");
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("client active...");
	}

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		ByteBuf byteBuf = (ByteBuf) msg;
		CharSequence s = byteBuf.getCharSequence(0, byteBuf.readableBytes(), CharsetUtil.UTF_8);
		System.out.println(s);
		ctx.writeAndFlush(byteBuf);
	}
}
